package com.mlink.ai.chat.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.mlink.ai.chat.assistant.robot.R
import com.mlink.ai.chat.assistant.robot.databinding.FragmentSettingBinding
import com.mlink.ai.chat.constants.COMMUNITY_GUIDE_LINES_URL
import com.mlink.ai.chat.constants.MYSELF_URL_IN_GOOGLE_PLAY
import com.mlink.ai.chat.constants.PRIVACY_POLICY_URL
import com.mlink.ai.chat.constants.TERMS_OF_SERVICE_URL
import com.mlink.ai.chat.ui.activity.AboutActivity
import com.mlink.ai.chat.ui.activity.FeedbackActivity
import com.mlink.ai.chat.utils.openUrl
import com.mlink.ai.chat.utils.searchMyselfOnPlayStore
import com.mlink.ai.chat.utils.shareText

class SettingFragment :BaseFragment<FragmentSettingBinding>() {


    override fun getViewBinding(): FragmentSettingBinding {
        return FragmentSettingBinding.inflate(LayoutInflater.from(context))
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView(){
        binding.aboutChatItem.title.text = resources.getString(R.string.about_ai_chat)
        binding.aboutChatItem.icon.setImageResource(R.drawable.ic_set_list_about)
        binding.aboutChatItem.root.setOnClickListener {
            startActivity(Intent(context, AboutActivity::class.java))
        }


        binding.termsItem.title.text = resources.getString(R.string.terms_of_service)
        binding.termsItem.icon.setImageResource(R.drawable.ic_set_list_terms)
        binding.termsItem.root.setOnClickListener {
            openUrl(TERMS_OF_SERVICE_URL)
        }

        binding.privacyItem.title.text = resources.getString(R.string.privacy_policy)
        binding.privacyItem.icon.setImageResource(R.drawable.ic_set_list_privacy)
        binding.privacyItem.root.setOnClickListener {
            openUrl(PRIVACY_POLICY_URL)
        }

        binding.setFeedbackItem.title.text = resources.getString(R.string.feedback_title)
        binding.setFeedbackItem.icon.setImageResource(R.drawable.ic_set_list_feedback)
        binding.setFeedbackItem.root.setOnClickListener {
            startActivity(Intent(context, FeedbackActivity::class.java))
        }

        binding.rateUsItem.title.text = resources.getString(R.string.rate_us)
        binding.rateUsItem.icon.setImageResource(R.drawable.ic_set_list_rate)
        binding.rateUsItem.root.setOnClickListener {
            openUrl(MYSELF_URL_IN_GOOGLE_PLAY)
        }

        binding.shareAppItem.title.text = resources.getString(R.string.share_the_app)
        binding.shareAppItem.icon.setImageResource(R.drawable.ic_set_list_share)
        binding.shareAppItem.root.setOnClickListener {
            doShareApp()
        }

    }

    private fun doShareApp() {
        val shareText = getString(R.string.share_app_text) + MYSELF_URL_IN_GOOGLE_PLAY
        shareText(shareText)
    }
}